const lazyLoadImage = (el, binding) => {
  el.intersectionObserver?.unobserve(el.parentElement);
  el.intersectionObserver = new IntersectionObserver((entries) => {
    if (entries[0].isIntersecting) {
      el.src = binding.value;
      el.intersectionObserver.unobserve(el.parentElement);
    }
  });
  // 开始监听
  el.intersectionObserver.observe(el.parentElement);
};
export const lazyLoad = {
  mounted: lazyLoadImage,
  updated: lazyLoadImage,
  beforeUnmount(el) {
    el.intersectionObserver.unobserve(el.parentElement);
  },
};

export default lazyLoad;
